package yu.vert.callback;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestCallBack {

    public void compute(final String s, final ComputeCallBack callBack) {
        //创建一个线程池
        ExecutorService pool = Executors.newFixedThreadPool(2);
        MyThread myThread = new MyThread(s);
        Future f1 = pool.submit(myThread);
        boolean tag = false;
        try {
            System.out.println(">>>"+f1.get().toString());
            callBack.success();
            tag = true;
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        if(!tag){
            callBack.fail();
        }
        //关闭线程池
        pool.shutdown();
    }

}
